package cn.swh.guguanjia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.swh.guguanjia.entity.WorkOrder;
import cn.swh.guguanjia.mapper.DetailMapper;
import cn.swh.guguanjia.mapper.TransferMapper;
import cn.swh.guguanjia.mapper.WorkOrderMapper;
import cn.swh.guguanjia.service.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class WorkOrderServicelmpl extends BaseServicelmpl<WorkOrder, Long> implements WorkOrderService {

    @Autowired
    WorkOrderMapper workOrderMapper;

    @Autowired
    DetailMapper detailMapper;

    @Autowired
    TransferMapper transferMapper;

    @Override
    public PageInfo<WorkOrder> selectPage(int pageNum, int pageSize, Map<String, Object> condition) {
        PageHelper.startPage(pageNum, pageSize);
        List<WorkOrder> examines = workOrderMapper.selectPage(condition);
        PageInfo<WorkOrder> pageInfo = new PageInfo<>(examines);
        return pageInfo;
    }

    @Override
    public Map<String, Object> selectById(long id) {
        Map<String, Object> work = workOrderMapper.selectById(id);
        List<Map<String, Object>> detail = detailMapper.selectById(id);
        List<Map<String, Object>> transfer = transferMapper.selectById(id);
        work.put("detail", detail);
        work.put("transfer", transfer);
        return work;
    }

}
